import {
    findInApply,
    batchDelInApply
} from "../../../api/afftersale/refacin";

let refacinman = {
    data() {
        return {
            search: {
                currentPage: 1,
                pageSize: 5,
                //创建时间
                startTime: "",
                endTime: "",

                //审核时间
                appStartTime: "",
                appEndTime: "",

                idoCode: "",//人库单号
                status: "",//返厂出库标志
                approveStatus: "",//审核状态
                approver: "",//审核人
                createBy: "",//制单人
            },

            //分页
            currentPage: 1,
            pageSize: 5,
            total: 0,
            //日期组件
            createTime: [],
            appTime: [],

            //申请列表
            applyList: [],
            //选中列表
            selectedApply: [],
        }
    },
    methods: {
        //每页条数变化
        handleSizeChange(pageSize) {
            this.pageSize = pageSize;
            this.search.currentPage = this.currentPage;
            this.search.pageSize = pageSize;
            this.find(this.search);
        },
        //页码改变
        handleCurrentChange(currentPage) {
            this.currentPage = currentPage;
            this.search.currentPage = currentPage;
            this.search.pageSize = this.pageSize;
            this.find(this.search);
        },

        //制单日期
        chooseTime() {
            this.search.startTime = this.createTime[0];
            this.search.endTime = this.createTime[1];
        },

        //审核日期
        applyChooseTime() {
            this.search.appStartTime = this.appTime[0];
            this.search.appEndTime = this.appTime[1];
        },

        //重置
        resetForm() {
            this.search = {
                currentPage: 1,
                pageSize: 5,
                //创建时间
                startTime: "",
                endTime: "",

                //审核时间
                appStartTime: "",
                appEndTime: "",

                idoCode: "",//入库单号
                status: "",//返厂出库标志
                approveStatus: "",//审核状态
                approver: "",//审核人
                createBy: "",//制单人
            };
            //日期组件
            this.createTime = [];
            this.appTime = [];
            this.find();
        },

        //批量删除
        delBatch() {
            let idList = [];
            this.selectedApply.forEach(value => {
                idList.push(value.id);
            });
            batchDelInApply(idList).then(value => {
                this.$message.success(value);
                this.find();
            })
        },

        //查询
        find(params) {
            let vm = this;
            if (params === null) {
                params = {
                    currentPage: vm.$data.currentPage,
                    pageSize: vm.$data.pageSize,
                }
            }
            findInApply(params).then(value => {
                vm.applyList = value.records;
                vm.total = value.total;
                console.log(vm.applyList)
            })
        },

        //检查是否可选择
        checkStatus(row) {
            return row.approveStatus !== 2;
        },

        //时间格式化
        creatFormatter(row) {
            if (row.createTime !== null) {
                return row.createTime.replace("T", " ");
            }
        },
        approveFormatter(row) {
            if (row.approverTime !== null) {
                return row.approverTime.replace("T", " ");
            }
        },

        //选中申请表
        handleSelectionChange(val) {
            this.selectedApply = val;
        },

        //搜索
        findPage() {
            this.find(this.search);
        },

        //跳转添加页面
        addApply() {
            this.$router.push({path: '/inApplyInfo', query: {flag: 2}});
        },

        //展示详情
        showInfo(id) {
            this.$router.push({path: '/inApplyInfo', query: {flag: 1, id: id}});
        },

        //修改跳转
        alter(id) {
            this.$router.push({path: '/inApplyInfo', query: {flag: 0, id: id}});
        },


    },
    created() {
        this.find();
    }
};

export default refacinman;